package com.zhan.signalling.store.elasticsearch;

import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import com.zhan.signalling.entity.ChatRecord;
import com.zhan.signalling.entity.WhiteBoardRecord;
import com.zhan.signalling.server.SocketServer;
import com.zhan.signalling.store.StoreMessageStore;


public class ESStoreMessageStore extends StoreMessageStore {
	
	protected RestHighLevelClient client;
	
	public final static String name = "elasticsearch";
	
	private ESStoreMessageStore(RestHighLevelClient client) {
		this.client = client;
	}
	
	
	public static ESStoreMessageStore getHandler(Properties prop) {
		final String host = prop.getProperty(SocketServer.STORE_MESSAGE_PROP+".elasticsearch.host");
		String[] hosts = host.split(",");
		HttpHost[] httpHosts = new HttpHost[hosts.length];
		for (int i = 0; i < hosts.length; i++) {
			httpHosts[i] = HttpHost.create(hosts[i]);
		}
		RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(httpHosts).build());
		return new ESStoreMessageStore(client);
	}


	@Override
	public long saveChat(ChatRecord message) {
		// TODO Auto-generated method stub
		return super.saveChat(message);
	}


	@Override
	public long saveWhiteBoard(WhiteBoardRecord message) {
		// TODO Auto-generated method stub
		return super.saveWhiteBoard(message);
	}


	@Override
	public List<Map<String,String>> getHistoryMessage(String platform, String groupId, Long seqId) {
		// TODO Auto-generated method stub
		return super.getHistoryMessage(platform, groupId, seqId);
	}

	
	
}
